package com.gxz.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxz.common.BasePageInfo;
import com.gxz.mapper.UserMapper;
import com.gxz.pojo.User;
import com.gxz.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User getById(Integer id) {
        return userMapper.getById(id);
    }

    @Override
    public PageInfo<User> getAll(BasePageInfo basePageInfo) {
        // 关键分页设置（紧贴查询语句）
        PageHelper.startPage(basePageInfo.getPageNum(), basePageInfo.getPageSize());
        List<User> users = userMapper.getAll(basePageInfo); // 执行查询
        return new PageInfo<>(users); // 包装分页结果
    }

    @Override
    public Integer create(User user) {
        return userMapper.create(user);
    }

    @Override
    public Integer update(User user) {
        return userMapper.update(user);
    }

    @Override
    public Integer delete(Integer id) {
        return userMapper.delete(id);
    }
}
